package org.example.apifallback.notice;

import com.intellij.notification.*;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;

/**
 * @author zengxiaoyu
 * @date 2025/7/31 16:52
 */
public class CommentNotice {

    public static void show(String content, Project project, Consumer<AnActionEvent> consumer) {
        // 创建通知分组（若未在plugin.xml注册）
        // 获取通知组
        NotificationGroup notificationGroup = NotificationGroupManager.getInstance()
                .getNotificationGroup("fallback.notice"); // 与plugin.xml中的id一致

        // 创建通知
        Notification notification = notificationGroup.createNotification(
                "插件提示",
                content,
                NotificationType.INFORMATION
        );

        // 添加操作按钮
        notification.addAction(new AnAction("确认") {
            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                // 点击逻辑
                // 执行传入的消费者函数
                consumer.accept(e);
            }
        });

        // 发送通知
        Notifications.Bus.notify(notification, project);
    }

    public static void show(String content, Project project) {
        // 创建通知分组（若未在plugin.xml注册）
        // 获取通知组
        NotificationGroup notificationGroup = NotificationGroupManager.getInstance()
                .getNotificationGroup("fallback.notice"); // 与plugin.xml中的id一致

        // 创建通知
        Notification notification = notificationGroup.createNotification(
                "插件提示",
                content,
                NotificationType.INFORMATION
        );
        // 发送通知
        Notifications.Bus.notify(notification, project);
    }

}
